/*
* berton
*/
package com.pitop.supplier.ctrl;

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import javax.annotation.Resource;
import java.util.List;
import java.util.HashMap;

import com.pitop.core.entity.BeanRet;
import com.pitop.core.entity.Page;
import com.pitop.core.tools.redis.RedisUtils;
import com.pitop.supplier.entity.Supplier;
import com.pitop.supplier.service.SupplierSV;

/**
* 供应商 控制器
*
* @author berton
*/
@RestController
@RequestMapping("/supplier")
@Slf4j
@Api(value = "供应商控制器", description = "供应商控制器")
public class SupplierCtrl {

    @Resource
    protected RedisUtils redisUtils;

    @Resource
    private SupplierSV supplierSV;

    /**
    * 查询Supplier一个详情信息
    * @param id 
    * @param code 编码
    * @return BeanRet
    */
    @ApiOperation(value = "查询Supplier一个详情信息", notes = "查询Supplier一个详情信息")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "",dataType = "java.lang.Long", paramType = "query"),
        @ApiImplicitParam(name = "code", value = "编码",dataType = "java.lang.String", paramType = "query")
    })
    @GetMapping(value = "/load")
    @ResponseBody
    public Supplier load(java.lang.Long id,java.lang.String code) {
        if(id==null){
        return null;
        }
        if(code==null){
        return null;
        }
        Supplier supplier = supplierSV.load(id,code);
        log.info(JSON.toJSONString(supplier));
        return supplier;
    }


    /**
    * 根据条件id查询Supplier一个详情信息
    *
    * @param id 
    * @return BeanRet
    */
    @ApiOperation(value = "查询Supplier一个详情信息", notes = "查询Supplier一个详情信息")
    @ApiImplicitParams({
       @ApiImplicitParam(name = "id", value = "",dataType = "java.lang.Long", paramType = "path")
    })
    @GetMapping(value = "/load/id/{id}")
    @ResponseBody
    public Supplier loadById(@PathVariable java.lang.Long id) {
        if(id==null){
           return null;
        }
        Supplier supplier = supplierSV.loadById(id);
        log.info(JSON.toJSONString(supplier));
        return supplier;
    }
    /**
    * 根据条件code查询Supplier一个详情信息
    *
    * @param code 编码
    * @return BeanRet
    */
    @ApiOperation(value = "查询Supplier一个详情信息", notes = "查询Supplier一个详情信息")
    @ApiImplicitParams({
       @ApiImplicitParam(name = "code", value = "编码",dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/code/{code}")
    @ResponseBody
    public Supplier loadByCode(@PathVariable java.lang.String code) {
        if(code==null){
           return null;
        }
        Supplier supplier = supplierSV.loadByCode(code);
        log.info(JSON.toJSONString(supplier));
        return supplier;
    }


    /**
    * 查询Supplier信息集合
    *
    * @return 分页对象
    */
    @ApiOperation(value = "查询Supplier信息集合", notes = "查询Supplier信息集合")
    @ApiImplicitParams({
    @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
    @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
        @ApiImplicitParam(name = "createTimeBegin", value = "创建时间", paramType = "query"),
        @ApiImplicitParam(name = "createTimeEnd", value = "创建时间", paramType = "query"),
        @ApiImplicitParam(name = "updateTimeBegin", value = "更新时间", paramType = "query"),
        @ApiImplicitParam(name = "updateTimeEnd", value = "更新时间", paramType = "query")
    })
    @PostMapping(value = "/list")
    @ResponseBody
    public List<Supplier> list(@RequestBody @ApiIgnore Supplier supplier,Integer curPage,Integer pageSize) {
        Page<Supplier> page=new Page<Supplier>(pageSize,curPage);
        List<Supplier> suppliers = supplierSV.list(supplier,page.genRowStart(),page.getPageSize());
        int total = supplierSV.count(supplier);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return suppliers;
    }


    /**
    * 查询Supplier信息集合
    *
    * @return 分页对象
    */
    @ApiOperation(value = "查询Supplier信息集合", notes = "查询Supplier信息集合")
    @ApiImplicitParams({
    @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
    @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
    @ApiImplicitParam(name = "id", value = "", paramType = "query"),
    @ApiImplicitParam(name = "code", value = "编码", paramType = "query")
    })
    @GetMapping(value = "/list/by")
    @ResponseBody
    public List<Supplier> listByPk(java.lang.Long id,java.lang.String code,Integer curPage,Integer pageSize) {
        Page<Supplier> page=new Page<Supplier>(pageSize,curPage);
        List<Supplier> suppliers = supplierSV.list(id,code, page.genRowStart(),page.getPageSize());
        int total = supplierSV.count(id,code);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return suppliers;
    }

    /**
    * 统计Supplier信息数量根据主键
    *
    * @return 总条数
    */
    @ApiOperation(value = " 统计Supplier信息数量根据主键", notes = " 统计Supplier信息数量根据主键")
    @ApiImplicitParams({
    @ApiImplicitParam(name = "id", value = "", paramType = "query"),
    @ApiImplicitParam(name = "code", value = "编码", paramType = "query")
    })
    @GetMapping(value = "/count/by")
    @ResponseBody
    public Integer count(java.lang.Long id,java.lang.String code) {
        return supplierSV.count(id,code);
    }

    /**
    * 统计Supplier信息数量
    *
    * @return 总条数
    */
    @ApiOperation(value = "统计Supplier信息数量", notes = "统计Supplier信息数量")
    @ApiImplicitParams({
    @ApiImplicitParam(name = "id", value = "", paramType = "query"),
    @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
    @ApiImplicitParam(name = "name", value = "供应商名称 最长32个汉字 64个英文", paramType = "query"),
    @ApiImplicitParam(name = "contacts", value = "联系人", paramType = "query"),
    @ApiImplicitParam(name = "bank", value = "最长32个汉字 64个英文", paramType = "query"),
    @ApiImplicitParam(name = "bankAccount", value = "开户行账户", paramType = "query"),
    @ApiImplicitParam(name = "creditRating", value = "信用等级", paramType = "query"),
    @ApiImplicitParam(name = "supplierCategoryCode", value = "供应商类型编码", paramType = "query"),
    @ApiImplicitParam(name = "address", value = "地址 64个汉字，128个英文字符", paramType = "query"),
    @ApiImplicitParam(name = "email", value = "电子邮箱", paramType = "query"),
    @ApiImplicitParam(name = "fax", value = "传真号", paramType = "query"),
    @ApiImplicitParam(name = "mobile", value = "移动电话", paramType = "query"),
    @ApiImplicitParam(name = "telephone", value = "固定电话", paramType = "query"),
    @ApiImplicitParam(name = "zipCode", value = "邮编", paramType = "query"),
    @ApiImplicitParam(name = "companyNature", value = "公司性质 国营 state-run ,民营privately operated，合资joint venture，外资 foreign capital", paramType = "query"),
    @ApiImplicitParam(name = "state", value = "状态：启用 enable,禁用 disable 
            ", paramType = "query"),
    @ApiImplicitParam(name = "summary", value = "备注 128 个汉字说明", paramType = "query"),
    @ApiImplicitParam(name = "createTime", value = "创建时间", paramType = "query"),
    @ApiImplicitParam(name = "updateTime", value = "更新时间", paramType = "query")
    })
    @PostMapping(value = "/count")
    @ResponseBody
    public Integer count(@RequestBody Supplier supplier) {
        if(supplier==null){
            return supplierSV.count(new HashMap());
        }else{
            return supplierSV.count(supplier);
        }
    }



    /**
    * 创建Supplier
    *
    * @return BeanRet
    */
    @ApiOperation(value = "创建Supplier", notes = "创建Supplier")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "name", value = "供应商名称 最长32个汉字 64个英文", paramType = "query"),
        @ApiImplicitParam(name = "contacts", value = "联系人", paramType = "query"),
        @ApiImplicitParam(name = "bank", value = "最长32个汉字 64个英文", paramType = "query"),
        @ApiImplicitParam(name = "bankAccount", value = "开户行账户", paramType = "query"),
        @ApiImplicitParam(name = "creditRating", value = "信用等级", paramType = "query"),
        @ApiImplicitParam(name = "supplierCategoryCode", value = "供应商类型编码", paramType = "query"),
        @ApiImplicitParam(name = "address", value = "地址 64个汉字，128个英文字符", paramType = "query"),
        @ApiImplicitParam(name = "email", value = "电子邮箱", paramType = "query"),
        @ApiImplicitParam(name = "fax", value = "传真号", paramType = "query"),
        @ApiImplicitParam(name = "mobile", value = "移动电话", paramType = "query"),
        @ApiImplicitParam(name = "telephone", value = "固定电话", paramType = "query"),
        @ApiImplicitParam(name = "zipCode", value = "邮编", paramType = "query"),
        @ApiImplicitParam(name = "companyNature", value = "公司性质 国营 state-run ,民营privately operated，合资joint venture，外资 foreign capital", paramType = "query"),
        @ApiImplicitParam(name = "state", value = "状态：启用 enable,禁用 disable 
            ", paramType = "query"),
        @ApiImplicitParam(name = "summary", value = "备注 128 个汉字说明", paramType = "query"),
        @ApiImplicitParam(name = "createTime", value = "创建时间", paramType = "query"),
        @ApiImplicitParam(name = "updateTime", value = "更新时间", paramType = "query")
    })
    @PostMapping("/build")
    @ResponseBody
    public Supplier build(@RequestBody @ApiIgnore Supplier supplier) {
        supplierSV.save(supplier);
        return supplier;
    }


    /**
    * 修改Supplier
    *
    * @return BeanRet
    */
    @ApiOperation(value = "修改Supplier", notes = "修改Supplier")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "", paramType = "query"),
        @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
        @ApiImplicitParam(name = "name", value = "供应商名称 最长32个汉字 64个英文", paramType = "query"),
        @ApiImplicitParam(name = "contacts", value = "联系人", paramType = "query"),
        @ApiImplicitParam(name = "bank", value = "最长32个汉字 64个英文", paramType = "query"),
        @ApiImplicitParam(name = "bankAccount", value = "开户行账户", paramType = "query"),
        @ApiImplicitParam(name = "creditRating", value = "信用等级", paramType = "query"),
        @ApiImplicitParam(name = "supplierCategoryCode", value = "供应商类型编码", paramType = "query"),
        @ApiImplicitParam(name = "address", value = "地址 64个汉字，128个英文字符", paramType = "query"),
        @ApiImplicitParam(name = "email", value = "电子邮箱", paramType = "query"),
        @ApiImplicitParam(name = "fax", value = "传真号", paramType = "query"),
        @ApiImplicitParam(name = "mobile", value = "移动电话", paramType = "query"),
        @ApiImplicitParam(name = "telephone", value = "固定电话", paramType = "query"),
        @ApiImplicitParam(name = "zipCode", value = "邮编", paramType = "query"),
        @ApiImplicitParam(name = "companyNature", value = "公司性质 国营 state-run ,民营privately operated，合资joint venture，外资 foreign capital", paramType = "query"),
        @ApiImplicitParam(name = "state", value = "状态：启用 enable,禁用 disable 
            ", paramType = "query"),
        @ApiImplicitParam(name = "summary", value = "备注 128 个汉字说明", paramType = "query"),
        @ApiImplicitParam(name = "createTime", value = "创建时间", paramType = "query"),
        @ApiImplicitParam(name = "updateTime", value = "更新时间", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public Supplier modify(@ApiIgnore Supplier supplier) {
        supplierSV.modify(supplier);
        return supplier;
    }

    /**
    * 删除Supplier
    *
    * @return BeanRet
    */
    @ApiOperation(value = "删除Supplier", notes = "删除Supplier")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "", paramType = "query"),
        @ApiImplicitParam(name = "code", value = "编码", paramType = "query")
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public BeanRet delete(java.lang.Long id,java.lang.String code) {
        supplierSV.delete(id,code);
        return BeanRet.create(true, "删除Supplier成功");
    }

}
